// TOWN SCRIPT
//    Town 0

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

reset_dialog();
add_dialog_str(0,"Ouch.",0);
add_dialog_str(1,"You slowly get to your feet, brushing away the dust and rock that clings to you. Wincing, you immediately wish you hadn't moved. Everywhere aches, and is tender to your touch.",0);
add_dialog_str(2,"What happened? Looking around you can see that you're in a fairly large cave, the floor of which is strewn with rubble and debris. Slowly it comes back to you. You were going... somewhere. You were walking down a long tunnel, when...",0);
add_dialog_str(3,"Looking up, far into the gloomy cave, you see a large hole in the rock above. The ground must've given way, and deposited you here. Wherever that is.",0);
add_dialog_str(4,"You feel for your gear - it's all there - but you don't find any clues as to where you were going when you fell. Never mind - in your current state your first priority is getting to a nearby settlement to rest...",0);
run_dialog(1);


break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

//Swamp
beginstate 10;
	if(get_flag(0,1) == 0) {
		message_dialog("A small trickle of falling water has - probably over many years - created a small swamp in this little cave. The mushrooms and fungi growing here are large and ripe - clearly no humans have been here to harvest the crop, at least for a while.","Perhaps if you take a closer look you can find something that would be useful for potion-crafting.");
		set_flag(0,1,1);
	}
break;



//Shrooms - potion making is 14
beginstate 11;
	if(get_flag(0,2) == 0) {
		if(get_skill_total(14) < 5) {
			message_dialog("You take a look at the plants growing here and spot two bunches of herbs that you know are useful for making healing potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(0,2,1);
			reward_give(214);
			reward_give(214);
			end();
		}
		if(get_skill_total(14) < 10) {
			message_dialog("You take a look at the plants growing here and spot three bunches of herbs that you know are useful for making healing potions.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(0,2,1);
			reward_give(214);
			reward_give(214);
			reward_give(214);
			end();
		}
		if(get_skill_total(14) > 10) {
			message_dialog("You take a look at the plants growing here and spot four bunches of herbs that you know are useful for making healing potions, and some toadstools.","You carefully take them, being careful not to damage them, and pack them away. Unfortunately nothing else in the patch of plants looks useful.");
			set_flag(0,2,1);
			reward_give(214);
			reward_give(214);
			reward_give(214);
			reward_give(214);
			reward_give(218);
			end();
		}
	} else {
		message_dialog("You've already searched this patch of herbs and mushrooms - there is nothing else here that looks useful to you.","");
		end();
	}
break;

//Moving town
beginstate 12;
	message_dialog("You move down this narrow tunnel - hopefully, you'll find some kind of civilization soon, and with any luck you'll avoid whatever beast you heard growling before.","");
	move_to_new_town(1,42,16);
break;

//Blocked exit
beginstate 13;
	if(get_flag(0,3) == 0) {
		message_dialog("This section of tunnel has been blocked off by rock and rubble - from the looks of it, a number of small cavequakes have, over the years, gradually built up on top of each other.","In another ten or twenty years, the tunnel will probably be completed closed off. You'll have to find another way out.");
		set_flag(0,3,1);
	}
break;

//Blocked corridor
beginstate 14;
	if(get_flag(0,4) == 0) {
		message_dialog("This tunnel has been made impassable - a barrier of rocks and rubble, probably shaken loose by a cavequake, has completely blocked the route. You'll have to find another way around if you wanted to explore the other side.","");
		set_flag(0,4,1);
	} else {
		message_dialog("This tunnel is still blocked up. You'll have to find another way around.","");
	}
break;

//Bat cavern
beginstate 15;
	if(get_flag(0,5) == 0) {
		message_dialog("As you enter this small, closed-off cave, you hear the high-pitched squealing of bats far above you. Looking up into the gloom you see a long shaft ascending into some caves higher up.","It's fortunate that the bats are so far away - in your weakened state you doubt you'd be able to fend off a large group of them.");
		set_flag(0,5,1);
	}
break;
		
//Shrooms in first chamber
beginstate 16;
	message_dialog("You take a look at the plants growing here but don't spot anything that is useful for making healing potions.","You move on.");
break;

//Leaving first chamber
beginstate 17;
	if(get_flag(0,6) == 0) {
		message_dialog("As you stumble away from where you landed, you look back over your shoulder. The cave floor is dotted with sharp stalagmites and broken rock - you are very fortunate to have avoided hitting any of them.","Grimacing slightly with the lingering pain of falling, you move on, eager to find somewhere safe to rest.");
		set_flag(0,6,1);
	}
break;

//ZOMG GROWL
beginstate 18;
	if(get_flag(0,7) == 0) {
		reset_dialog();
		add_dialog_str(0,"Walking down this gently-sloping passage you suddenly wonder why it's so quiet - apart from the occasional drip of water and the ever-present sound of bats, the caves are silent.",0);
		add_dialog_str(1,"Then, as if on cue, you hear a low ominous growl far off in the distance. Hopefully, whatever made it is far away from you - judging from the sound of it, it's huge.",0);
		add_dialog_str(2,"Gripping your weapons a little more tightly, you press on.",0);
		run_dialog(1);
		set_flag(0,7,1);
	}
break;